package com.example.barcodeapp;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.PaintDrawable;
import android.os.Bundle;
import android.text.Editable;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.bumptech.glide.Glide;
import com.example.barcodeapp.adapter.FragmentAdapter;
import com.example.barcodeapp.ui.home.fragment.GatherFragment;
import com.example.barcodeapp.ui.huodong.FragmentHuoDong;
import com.example.barcodeapp.ui.own.fragment.OwnFragment;
import com.example.barcodeapp.ui.wode.FragmentWoDe;
import com.google.android.material.tabs.TabLayout;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    ViewPager viewPager;
    private TabLayout tabLayout;
    private ArrayList<Fragment> fragments;
    private FragmentAdapter fragmentAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        viewPager = (ViewPager) findViewById(R.id.viewPager);
        tabLayout = (TabLayout) findViewById(R.id.tabLayout);

        fragments = new ArrayList<>();
        //首页
        fragments.add(new GatherFragment(MainActivity.this));
        //课程
        fragments.add(new OwnFragment());
        //活动
        fragments.add(new FragmentHuoDong());
        //我的
        fragments.add(new FragmentWoDe());

        fragmentAdapter = new FragmentAdapter(getSupportFragmentManager(), fragments);
        viewPager.setAdapter(fragmentAdapter);
        tabLayout.setupWithViewPager(viewPager);
        tabLayout.setTabIconTint(null);//显示图片
        tabLayout.getTabAt(0).setText("首页").setIcon(R.drawable.tab1);
        tabLayout.getTabAt(1).setText("课程").setIcon(R.drawable.tab2);
        tabLayout.getTabAt(2).setText("活动").setIcon(R.drawable.tab3);
        tabLayout.getTabAt(3).setText("我的").setIcon(R.drawable.tab4);
        initActivity();
    }

    private void initActivity() {

    }

    public void zhuan() {
        tabLayout.getTabAt(1).select();
    }
}